<?PHP
defined('_XR_EXEC') or die();
/**
 * 控制器处理类 
 */
class body_controller extends controller{
	function __construct(){
		parent::__construct();
	}
	public function index__(){
		$other = factory::getcfg('other',array(),'body');
		$this->assign('other',$other);
	 
		if (strtoupper($_SERVER['REQUEST_METHOD']) == 'POST')
		{
				$fen = json_decode($_POST['fen']);
				$rs = array();
				foreach($other as $k=>$v){
				  $tiaomu_num = count($v['lib']);
					$temparr = array(
						'name'=>$v['name'],
						'fen'=>$fen[$k],
						'zhuan'=>func::fnDec( (($fen[$k] - $tiaomu_num)/($tiaomu_num*4))*100 ),
						'body'=>'0' //0：否    1：倾向    2：是
					);
					$rs[] = $temparr;
				}
				# 其他气质是否均小于30
				$below_thirty = true;
				foreach($rs as $k=>$v){
					if($k>0){
						if($v['zhuan']>=30){
							$below_thirty = false;
						}
					}
				}	
				# 其他气质是否均小于40
				$below_fourty = true;
				foreach($rs as $k=>$v){
					if($k>0){
						if($v['zhuan']>=40){
							$below_fourty = false;
						}
					}
				}
				# 平和质结果
				$rs_ping = $rs[0];
				unset($rs[0]);
				if($rs_ping['zhuan']>=60 && $below_fourty){
					$rs_ping['body'] = '1';
				}
				if($rs_ping['zhuan']>=60 && $below_thirty){
					$rs_ping['body'] = '2';
				}
				foreach($rs as &$v){
					if($v['zhuan']>=40){
						$v['body']='2';
					}else if($v['zhuan']>=30 && $v['zhuan']<40){
						$v['body']='1';
					}else{
						$v['body']='0';
					}
			  }
				#  主类型
				$main_body = array();
				# 偏向类型
				$pian_body = array();
				if($rs_ping['zhuan']>=60 && $below_thirty){
					$main_body[] = '平和质';
				}else if($rs_ping['zhuan']>=60 && $below_fourty){
					$main_body[] = '基本为平和质';
				}
				foreach($rs as &$v){
					 if($v['body']=='2'){
							$main_body[] = $v['name'];
					 }
					 if($v['body']=='1'){
							$pian_body[] = $v['name'];
					 }
				}
				exit('{"success":1,"main_body":'.json_encode($main_body).',"pian_body":'.json_encode($pian_body).'}');
			 
		}
	}

	 
	
	 
}
?>